
<?php  
   //index.php   
  
    require_once 'model/global.inc.php';  
    $error = "";  
    $username = "";  
    $password = "";  

    //check to see if they've submitted the login form  
    if(isset($_POST['submit-login'])) {  

        $username = $_POST['username'];  
        $password = $_POST['password'];  

        $userTools = new UserTools();  
        if($userTools->login($username, $password)){  
                //successful login, redirect them to a page 
            $user = unserialize($_SESSION['user']);
            $memid = $user->memid;
            echo $memid;
            $ip=$_SERVER['REMOTE_ADDR'];
            $last_date = date("Y-m-d H:i:s",time());
            $sql = "update tblmember set last_ip = '$ip',last_joined_datetime = '$last_date' where memid = '$memid'";
            mysql_query($sql) or die(mysql_error());  
                header("Location: index.php");  
        }else{  
            $error = "Incorrect username or password. Please try again.";  
        }  
    }  
?>  
<div class="top-header">
    <div class="logo">
        <a href="index.php" ><img src="view/images/logo.png"/></a>
    </div>
    <div class="top-right">
        <div class="languaqe">
            <img src="view/images/laco.jpg"/>
        </div>
        <div id="form-login">
                    <?php  
                        if($error != "")  
                        {  
                        echo $error."<br/>";  
                        }  
                    ?>  
                    <form action="" method="post">  
                        <input type="text" name="username" value="Username/Email" onClick="(this.value='')"  /> 
                        <input type="password" name="password" value="Password" onClick="(this.value='')"  />  
                        <input type="submit" value="Login" name="submit-login" />  
                    </form>
        </div>
        <div class="login">     
            <table align="right">      
                    <tr>
                            <td>
                                    <?php if(isset($_SESSION['logged_in'])) : ?>  
                                    <?php $user = unserialize($_SESSION['user']); ?>  
                                            <?php echo "<script>document.getElementById('form-login').style.display='none';</script>"; ?>
                                            Hello, <?php echo $user->username; ?>. You are logged in. <a href="view/login/logout.php">Logout</a>
                                    <?php else : ?>  
                                            <a href="">Forgot password?</a> | Not member yet? <a href="register_member.php">Register now</a>  
                                    <?php endif; ?>  
                            </td>
                    </tr>
            </table>
        </div>
    </div>
</div>

<div id="menu" >
    <ul>
        <li>
            <a href="index.php" >Home</a> |
        </li>
        <li id="myaccount">
            <a href="myaccount.php"> My Account </a> |
        </li>
        <li id="hidden_register">
            <a href="register_member.php">Register</a>    |
        </li>
        <li>
            Help
        </li>
    </ul>
    <?php
        if(!isset($_SESSION['logged_in']))
        {
            echo "<script>document.getElementById('myaccount').style.display='none';</script>";
        }
        else{
            echo "<script>document.getElementById('hidden_register').style.display='none';</script>";
        }
    ?>
</div>
<div class="menu1">
    <img src="view/images/menu.jpg" width="1000px"/>
</div>